<?php

namespace app\common\model;

use think\Model;
use think\Db;

/**
 * 拼团模型
 */
class TeamActivity extends Model
{
    protected $append = [
        'goods_guige_text'
    ];

    public function goods(){
        return $this->belongsTo('Goods','goods_id','id')
            ->field('id,image,market_price');
    }

    public function getGoodsGuigeTextAttr($value,$data){
        $goodsAttrData = Db::name('goods_attr')->alias('ga')
            ->join('attr a','ga.attr_id = a.id','LEFT')
            ->where(['goods_id' => $data['goods_id']])
            ->field('a.name')
            ->find();
        $attrName = $goodsAttrData['name'];

        $goodsAttrM = model('common/goodsAttr');
        $goodsAttr = [];
        if($data['item_id']){
            $goodsAttr = $goodsAttrM->field('id,attr_value')->where(['id' => $data['item_id']])->find();
        }


        $data = [
            'attrName' => $attrName,
            'goodsAttr' => $goodsAttr
        ];
        return $data;
    }

}